<?php
/**
 * ****************************************************************************
 *  - TDMDownloads By TDM   - TEAM DEV MODULE FOR XOOPS
 *  - GNU Licence Copyright (c)  (www.xoops.org)
 *
 * La licence GNU GPL, garanti à l'utilisateur les droits suivants
 *
 * 1. La liberté d'exécuter le logiciel, pour n'importe quel usage,
 * 2. La liberté de l' étudier et de l'adapter à ses besoins,
 * 3. La liberté de redistribuer des copies,
 * 4. La liberté d'améliorer et de rendre publiques les modifications afin
 * que l'ensemble de la communauté en bénéficie.
 *
 * @copyright   http://www.tdmxoops.net
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
 * @author		TDM (G.Mage); TEAM DEV MODULE
 *
 * ****************************************************************************
 */

include 'admin_header.php';
//Affichage de la partie haute de l'administration de Xoops
xoops_cp_header();
//On recupere la valeur de l'argument op dans l'URL$
if (isset($_REQUEST['op'])) {
	$op = $_REQUEST['op'];
} else {
	$op = 'liste';
}

//appel des class
//$downloadscat_Handler =& xoops_getModuleHandler('tdmdownloads_cat', 'TDMDownloads');
$downloads_Handler =& xoops_getModuleHandler('tdmdownloads_downloads', 'TDMDownloads');
$downloadsbroken_Handler =& xoops_getModuleHandler('tdmdownloads_broken', 'TDMDownloads');
$downloadsmod_Handler =& xoops_getModuleHandler('tdmdownloads_mod', 'TDMDownloads');

//appel du menu admin
if ( !is_readable(XOOPS_ROOT_PATH . "/Frameworks/art/functions.admin.php"))	{
    tdmdownloads_adminmenu(1, _MI_TDMDOWNLOADS_ADMENU1);
} else {
    include_once XOOPS_ROOT_PATH.'/Frameworks/art/functions.admin.php';
    loadModuleAdminMenu (1, _MI_TDMDOWNLOADS_ADMENU1);
}

// compte le nombre de téléchargements
$criteria = new CriteriaCompo();
$criteria->add(new Criteria('status', 0, '!='));
$nb_downloads = $downloads_Handler->getCount($criteria);
// compte le nombre de téléchargements en attente de validation
$criteria = new CriteriaCompo();
$criteria->add(new Criteria('status', 0));
$nb_downloads_waiting = $downloads_Handler->getCount($criteria);
// compte le nombre de rapport de téléchargements brisés
$nb_broken = $downloadsbroken_Handler->getCount();
// compte le nombre de demande de modifications
$nb_modified = $downloadsmod_Handler->getCount();

if (phpversion() >= 5){
    include_once XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->dirname().'/class/menu.php';
    //showIndex();
    $menu = new tdmdownloadsMenu();
    $menu->addItem('Category', 'category.php', '../images/icon/doc.png', _MI_TDMDOWNLOADS_ADMENU2);
    $menu->addItem('Downloads', 'downloads.php', '../images/icon/telecharger.png', _MI_TDMDOWNLOADS_ADMENU3);
    $menu->addItem('Broken', 'broken.php', '../images/icon/broken.png', _MI_TDMDOWNLOADS_ADMENU4);
    $menu->addItem('Modified', 'modified.php', '../images/icon/modified.png', _MI_TDMDOWNLOADS_ADMENU5);
    $menu->addItem('Champ', 'field.php', '../images/icon/field.png', _MI_TDMDOWNLOADS_ADMENU6);
    $menu->addItem('About', 'about.php', '../images/icon/about.png', _MI_TDMDOWNLOADS_ADMENU7);
    $menu->addItem('Permissions', 'permissions.php', '../images/icon/permissions.png', _MI_TDMDOWNLOADS_ADMENU8);
    $menu->addItem('Update', '../../system/admin.php?fct=modulesadmin&op=update&module=TDMDownloads', '../images/icon/update.png', _MI_TDMDOWNLOADS_ADMENU9);
    $menu->addItem('Imort', 'import.php', '../images/icon/import.png', _MI_TDMDOWNLOADS_ADMENU10);
    $menu->addItem('Preference', '../../system/admin.php?fct=preferences&amp;op=showmod&amp;mod=' . $xoopsModule ->getVar('mid') . '&amp;&confcat_id=1', '../images/icon/pref.png', _PREFERENCES);	
    echo $menu->getCSS();

    echo '<table width="100%" border="0" cellspacing="10" cellpadding="4">';
    echo '<tr><td>' . $menu->render() . '</td>';
}else{
    echo '<table width="100%" border="0" cellspacing="10" cellpadding="4">';
    echo '<tr><td><div class="errorMsg" style="text-align: left;">' . _MI_TDMDOWNLOADS_INDEX_ERREURPHP . '</div></td>';
}
echo '<td valign="top" width="60%">';
echo '<fieldset><legend class="CPmediumTitle">' . _MI_TDMDOWNLOADS_ADMENU3 . '</legend><br/>';
printf(_AM_TDMDOWNLOADS_INDEX_DOWNLOADS,$nb_downloads);
echo '<br /><br />';
printf(_AM_TDMDOWNLOADS_INDEX_DOWNLOADSWAITING,$nb_downloads_waiting);
echo '<br/></fieldset><br /><br />';

echo '<fieldset><legend class="CPmediumTitle">' . _MI_TDMDOWNLOADS_ADMENU4 . '</legend><br/>';
printf(_AM_TDMDOWNLOADS_INDEX_BROKEN,$nb_broken);
echo '<br/></fieldset><br /><br />';

echo '<fieldset><legend class="CPmediumTitle">' . _MI_TDMDOWNLOADS_ADMENU5 . '</legend><br/>';
printf(_AM_TDMDOWNLOADS_INDEX_MODIFIED,$nb_modified);
echo '<br/></fieldset><br /><br />';


echo '</td></tr>';
echo '</table>';

// message d'erreur si la copie du dossier dans uploads n'a pss marché à l'installation
$url_folder = XOOPS_ROOT_PATH . '/uploads/TDMDownloads/';
if (!is_dir($url_folder)){
    echo '<div class="errorMsg" style="text-align: left;">' . sprintf(_MI_TDMDOWNLOADS_INDEX_ERREURPFOLDER, XOOPS_ROOT_PATH) . '</div>'; 
}

//système pour indiquer si l'on utilise la dernière version
moduleLastVersionInfo( $GLOBALS['xoopsModule']->getVar('version'), $xoopsModule->dirname() );

echo '<div align="center"><a href="http://www.tdmxoops.net" target="_blank"><img src="http://www.tdmxoops.net/images/logo_modules.gif" alt="TDM" title="TDM"></a></div>';
//Affichage de la partie basse de l'administration de Xoops
xoops_cp_footer();
?>